package com.phospherus.test

import com.fasterxml.jackson.databind.ObjectMapper
import com.phospherus.flow.entity.BusinessAudit
import com.phospherus.flow.service.FormInstBaseService
import org.junit.Test
import java.io.File
import java.time.LocalDate
import java.time.format.DateTimeFormatter

/**
 * @author songjinlong
 * @version 1.0
 * @since 2017/11/10
 */
class CodeCreate {
    @Test
    fun test() {
        var classNames = arrayOf("WorkFlowInst")
        var packageName = "flow"
        var author = "songjinlong"
        var format = DateTimeFormatter.ofPattern("yyyy/MM/dd")
        var localDay = LocalDate.now().format(format)
        var basePath = "/Users/songjinlong/WorkSpace/ous/src/phospherus/src/main/java/com/phospherus/${packageName}/"
        var file = File(basePath+"repository")
        file.mkdirs()
        file = File(basePath+"service")
        file.mkdirs()
        file = File(basePath+"controller")
        file.mkdirs()
        for (str in classNames) {
            var repository = "package com.phospherus.${packageName}.repository\n" +
                    "\n" +
                    "import com.phospherus.common.repository.BaseRepository\n" +
                    "import com.phospherus.${packageName}.entity.${str}\n" +
                    "\n" +
                    "/**\n" +
                    " * @author ${author}\n" +
                    " * @version 1.0\n" +
                    " * @since ${localDay}\n" +
                    " */\n" +
                    "interface ${str}Repository : BaseRepository<${str}, Long>"
            val repositoryFile = File(basePath + "repository", "${str}Repository.kt")
            repositoryFile.writeText(repository)

            val service = "package com.phospherus.${packageName}.service\n" +
                    "\n" +
                    "import com.phospherus.common.service.impl.BaseServiceImpl\n" +
                    "import com.phospherus.${packageName}.entity.${str}\n" +
                    "import com.phospherus.${packageName}.repository.${str}Repository\n" +
                    "import org.springframework.stereotype.Service\n" +
                    "\n" +
                    "/**\n" +
                    " * @author ${author}\n" +
                    " * @version 1.0\n" +
                    " * @since ${localDay}\n" +
                    " */\n" +
                    "@Service\n" +
                    "class ${str}Service : BaseServiceImpl<${str}, Long, ${str}Repository>()"
            val serviceFile = File(basePath + "service", "${str}Service.kt")
            serviceFile.writeText(service)

//            val controller = "package com.phospherus.${packageName}.controller\n" +
//                    "\n" +
//                    "import com.phospherus.common.controller.BaseSaveController\n" +
//                    "import com.phospherus.${packageName}.entity.${str}\n" +
//                    "import com.phospherus.${packageName}.service.${str}Service\n" +
//                    "import org.springframework.stereotype.Controller\n" +
//                    "import org.springframework.web.bind.annotation.RequestMapping\n" +
//                    "\n" +
//                    "/**\n" +
//                    " * @author ${author}\n" +
//                    " * @version 1.0\n" +
//                    " * @since ${localDay}\n" +
//                    " */\n" +
//                    "@Controller\n" +
//                    "@RequestMapping(\"/${packageName}/${str.toLowerCase()}\")\n" +
//                    "class ${str}Controller : BaseSaveController<${str}, ${str}Service>()"
//            val controllerFile = File(basePath + "controller", "${str}Controller.kt")
//            controllerFile.writeText(controller)
        }
    }
}